
package editeur;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.*;
import java.io.File;
import java.io.Serializable;

import javax.imageio.ImageIO;
import javax.swing.JFileChooser;


public class Photo  extends BufferedImage implements Serializable{

	

    /**
     * 
     */
    private static final long serialVersionUID = 1764482787482625146L;
    private String nom;
    //private int posX, posY;
    
    public String getNom(){
        return nom;
    }
    
  /*  
    public int getPosX() {
		return posX;
	}


	public void setPosX(int posX) {
		this.posX = posX;
	}


	public int getPosY() {
		return posY;
	}


	public void setPosY(int posY) {
		this.posY = posY;
	}
*/

	public Photo(String nom,BufferedImage img){
            super(img.getWidth(),img.getHeight(),BufferedImage.TYPE_INT_RGB);
            this.setData(img.getData());
            this.nom=nom;
            //posX=0;
            //posY=0;
            
    }
    
    public Photo(String nom,BufferedImage img,int x,int y)
    {
        super(img.getWidth(),img.getHeight(),BufferedImage.TYPE_INT_RGB);
        this.setData(img.getData());
        this.nom=nom;
        //posX=x;
        //posY=x;
}

    public  void Load() {  
    BufferedImage bimg = null; 
    String ref;
    JFileChooser fc = new JFileChooser();
    File file=null;
    int returnVal=fc.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION)
    {
            file = fc.getSelectedFile();
            ref=file.getAbsolutePath();
             try {  
             bimg = ImageIO.read(new File(ref));  
         } catch (Exception e) {  
             e.printStackTrace();  
         }        
    }
    this.setData(bimg.getData());
   }

    public static BufferedImage resize(BufferedImage img, int newW, int newH) {  
    int w = img.getWidth();  
    int h = img.getHeight();  
    BufferedImage dimg = new BufferedImage(newW, newH, img.getType());  
    Graphics2D g = dimg.createGraphics();  
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);  
    g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);  
    g.dispose();  
    return dimg;  
	}  

	 public void dessine(Graphics2D g)
     {
 		g.drawImage(this,null,20,20);
 		//g.setColor(Color.black);
 		//g.fillOval(100,100, 100, 100);
     }
	 public void dessineP(Graphics2D g, int x, int y,int taille)
     {
 		g.drawImage(this, 0, 0, taille,taille,null);
     }

}

